package com.gjx.clock

import java.text.SimpleDateFormat
import java.util.*

object TimeFormatHelper {
    private var simpleDateFormat = SimpleDateFormat("yyyy年MM月dd日 HH:mm")
    fun timeFormat(triggerAtMillis:Long):String{
        val now = Calendar.getInstance()
        val nowDay = now.get(Calendar.DATE)

        val triggerDate = Date(triggerAtMillis)
        val trigger = Calendar.getInstance()
        trigger.timeInMillis = triggerAtMillis
        val triggerDay = trigger.get(Calendar.DATE)

        if(nowDay==triggerDay){
            simpleDateFormat = SimpleDateFormat("今天 HH:mm")
        }
        if(nowDay==triggerDay-1){
            simpleDateFormat = SimpleDateFormat("明天 HH:mm")
        }
        if(nowDay==triggerDay-2){
            simpleDateFormat = SimpleDateFormat("后天 HH:mm")
        }

        return simpleDateFormat.format(triggerDate)
    }
}